package com.mass.core.sys.dict.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.mass.core.sys.dict.model.SysDictVal;
import com.mass.core.sys.dict.service.SysDictValService;
import com.mass.core.utils.AjaxResponse;

import java.util.List;
import java.util.Map;

/**
 * 数据字典公共接口</p>
 * created by pannan on 2017/6/22
 * 
 */
@RestController
@RequestMapping(value = "/dictionary")
public class DictionaryController {

    private final static Logger LOGGER = LoggerFactory.getLogger(DictionaryController.class);

    @Autowired
    private SysDictValService sysDictValService;

    /**
     *根据词典类型 编码查询
     *@param typeCodes  数据字典类型编码
     **/
    @RequestMapping(value="/selectListByTypeCode", method = RequestMethod.GET)
    public AjaxResponse selectListByTypeCode(@RequestParam("typeCodes") String[] typeCodes){
        try {
            Map<String,Object> mapList = this.sysDictValService.selectListByTypeCode(typeCodes);
            return AjaxResponse.success("ok", mapList);
        }catch (Exception e){
            LOGGER.error("SysDictVal getByTypeCode error!",e);
            return AjaxResponse.error("error");
        }
    }


    @RequestMapping(value="/selectByTypeCode", method = RequestMethod.GET)
    public AjaxResponse selectByTypeCode(@RequestParam("typeCode") String typeCode){
        try {
            List<SysDictVal> ValList = this.sysDictValService.selectByTypeCode(typeCode);
            return AjaxResponse.success("ok", ValList);
        }catch (Exception e){
            LOGGER.error("SysDictVal getByTypeCode error!",e);
            return AjaxResponse.error("error");
        }
    }


}
